package com.example.qianfeng.image.stream;

import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 定时任务配置类
 */
@Configuration
public class QuartzConfig {
    /**
     * 注入 bean 添加一个定时任务
     * @return JobDetail
     */
    @Bean
    public JobDetail deleteDetail() {
        return JobBuilder.newJob(DeleteQuartz.class)
                .withIdentity("delete outTime images")
                .usingJobData("job_delete", "delete images")
                .storeDurably()
                .build();
    }

    /**
     * 注入 bean 执行定时任务中的触发器
     * @return Trigger
     */
    @Bean
    public Trigger deleteTrigger() {
        return TriggerBuilder.newTrigger()
                .forJob(deleteDetail())
                .withIdentity("deleteTrigger")
                .usingJobData("trigger_delete", "delete images")
                .withSchedule(CronScheduleBuilder.cronSchedule("*/5 * * * * ? *"))
                .build();
    }
}
